/*
 * messages.c
 *
 *  Created on: 2015-03-21
 *      Author: root
 */
#include "messages.h"

#ifndef MESSAGES_H_
#define MESSAGES_H_
#include "messages.h"

#endif


void md(void)
{
	ROM_SysCtlDelay(999);
}
void mdd(void)
{
	ROM_SysCtlDelay(999999);
}
void welcome(void)
{
	load_welcome_screen(1);
	load_welcome_screen(0);
	int temp=0;
	/*bt_UARTsend("\033[31m");
	bt_UARTsend(" +---------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("--------+");md();bt_UARTsend("\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend("  _____    _____");md();bt_UARTsend("_  __   __  ____");md();bt_UARTsend("__  ______  ____");md();bt_UARTsend("__      |\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend(" /\\  __`-./\\  __");md();bt_UARTsend(" \\ \\ \\ /\\ \\ \\  _");md();bt_UARTsend("__\\/\\  ___\\ \\  _");md();bt_UARTsend("_ \\     |\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend("/  \\ \\ `\\ \\ \\ \\_");md();bt_UARTsend("\\ \\ \\ `-.\\ \\ \\ \\");md();bt_UARTsend(" ___ \\ \\__   \\ \\");md();bt_UARTsend("_\\ \\    |\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend("\\   \\ \\  \\ \\ \\  ");md();bt_UARTsend("_  \\ \\      \\ \\ ");md();bt_UARTsend("\\\\_ \\ \\  _\\   \\ ");md();bt_UARTsend(" __`.   |\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend(" \\   \\ \\_/ |  \\ \\");md();bt_UARTsend(" \\ \\ \\ \\`-. \\ \\ ");md();bt_UARTsend("\\_\\ \\ \\ \\____ \\ ");md();bt_UARTsend("\\ \\ \\  |\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend("  \\   \\____/   \\");md();bt_UARTsend(" \\ \\_\\ \\_\\  \\_\\ ");md();bt_UARTsend("\\_____\\ \\_____\\ ");md();bt_UARTsend("\\_\\ \\ \\ |\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend("   \\  /   / \\  /");md();bt_UARTsend(" / / / / /  / / ");md();bt_UARTsend("/     / /     / ");md();bt_UARTsend("/ / / / |\r\n");md();
	bt_UARTsend(" | ");md();bt_UARTsend("    \\/___/   \\/_");bt_UARTsend("/\\/_/ /_/ \\/_/ /");md();bt_UARTsend("_____/ /_____/ /");md();bt_UARTsend("_/\\/_/  |\r\n");md();
	bt_UARTsend(" |              ");bt_UARTsend("                ");bt_UARTsend("                ");bt_UARTsend("           |\r\n");
	md();bt_UARTsend(" +---------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("--------+");md();bt_UARTsend("\r\n");md();
	bt_UARTsend("\033[0m");*/

	bt_UARTsend("\r\n");
	md();//


	bt_UARTsend("Loading:  ");
	md();//ROM_SysCtlDelay(15000000);
	bt_UARTsend("\033[42m");
	for (temp=0 ; temp < 40 ; temp++ )
	{
		bt_UARTputc(' ');
		md();//md();md();md();md();
		md();//md();md();md();md();
	}
	bt_UARTsend("\033[0m");

	//bt_UARTsend("\r\n");
	//bt_UARTsend("\033[0m");

	bt_UARTsend("\033[42m");
	bt_UARTsend("\tOK");
	bt_UARTsend("\033[0m");

	md();//ROM_SysCtlDelay(30000000);
	bt_UARTsend("\033[0m");
	bt_UARTsend("\r\n");
	bt_UARTsend("\r\n");



}

void welcomeMessage(void)
{
	//Send init message over bluetooth when paired and ready to go
	bt_UARTsend("\033[2J");				//clear screen
	welcome();
	bt_UARTsend("Initializing System");
	loading_bar(16);
	load_okfail(1);

	bt_UARTsend("\033[33m");
	bt_UARTsend("Welcome to Stellarilink\r\n");
	bt_UARTsend("\033[0m");
}

void debugHeader(void)
{
	bt_UARTsend("\r\n");
	bt_UARTsend("Main loop running at full speed\r\n\r\n");
	bt_UARTsend("ADC:\tBB1\tBB2\t");
	bt_UARTsend("BB3\tHE1\tHE2\tStep\r\n");
}
void debugPrint(void)
{
	int calc[4];
	calc[1] = gADCvalue%1000;
	calc[2] = calc[1]%100;
	calc[3]  = calc[2]%10;
	calc[0]=gADCvalue;
	calc[0]=calc[0]/1000;
	calc[1]=calc[1]/100;
	calc[2]=calc[2]/10;

	bt_UARTsend("\033[32m");
	bt_UARTsend("\033[8m");
	//bt_UARTsend("\033[45;1H");
	bt_UARTsend("\b\b\b\b\b\b\b");
	bt_UARTsend("\b\b\b\b\b\b\b\b\b");
	bt_UARTsend("\b\b\b\b\b\b\b\b\b");
	bt_UARTsend("\b\b\b\b\b\b\b\b\b");
	bt_UARTsend("\b\b\b\b\b\b\b\b\b");
	bt_UARTsend("\b\b\b\b\b\b");
	//bt_UARTsend("\b");
	bt_UARTputc(48+calc[0]);
	bt_UARTputc(48+calc[1]);
	bt_UARTputc(48+calc[2]);
	bt_UARTputc(48+calc[3]);
	bt_UARTsend("\t");
	bt_UARTputc(48+gOutput[0]+2*gStateChange[0]);
	bt_UARTsend("\t");
	bt_UARTputc(48+gOutput[1]+2*gStateChange[1]);
	bt_UARTsend("\t");
	bt_UARTputc(48+gOutput[2]+2*gStateChange[2]);
	bt_UARTsend("\t");
	bt_UARTputc(48+gOutput[3]+2*gStateChange[3]);
	bt_UARTsend("\t");
	bt_UARTputc(48+gOutput[4]+2*gStateChange[4]);
	bt_UARTsend("\t");
	bt_UARTputc(48+_gCurrentStep);
	//bt_UARTputc(' ');
	//bt_UARTsend("\r");
	bt_UARTsend("\033[0m");

}

void loading_bar(int length)
{
	int temp;
	bt_UARTsend(" ");
	//bt_UARTsend("\033[42m");
	for (temp=0 ; temp < (length+14) ; temp++ )
	{
		if((length - temp) == 5) bt_UARTsend("\033[42m");
		bt_UARTputc(' ');
		md();//md();md();md();md();
		md();//md();md();md();md();
	}
	bt_UARTsend("\033[0m");
	bt_UARTsend(" ");
}

void load_okfail(int cond)
{
	if(cond)
	{
		bt_UARTsend("\033[42m");
		bt_UARTsend("\tOK");
		bt_UARTsend("\033[0m");
		bt_UARTsend("\r\n");
	}
	else
	{
		bt_UARTsend("\033[41m");
		bt_UARTsend("\tFail");
		bt_UARTsend("\033[0m");
		bt_UARTsend("\r\n");
	}
}

void load_welcome_screen(int choice)
{
	switch(choice)
	{
		case 0: {
					int temp1, temp2;
					bt_UARTsend("\033[42m");
					for(temp1 = 0; temp1 < 2; temp1++)
					{
						bt_UARTsend("\033[42m");
						for(temp2 = 0; temp2 < 60; temp2++)
						{
							bt_UARTsend(" ");
						}
						bt_UARTsend("\033[0m");
						bt_UARTsend("\r\n");
					}
					bt_UARTsend("\033[42m");
					bt_UARTsend("  ###  #       ##  ##              #  ##   #         ##     \033[0m\r\n");
					bt_UARTsend("\033[42m");
					bt_UARTsend(" #  #  #        #   #                  #              #     \033[0m\r\n");
					bt_UARTsend("\033[42m");
					bt_UARTsend(" #     #        #   #                  #              #     \033[0m\r\n");
					bt_UARTsend("\033[42m");
					bt_UARTsend("  #   ###  ##   #   #  ####  #### ##   #  ##  #####   #  ## \033[0m\r\n");
					bt_UARTsend("\033[42m");
					bt_UARTsend("   ##  #  #  #  #   #     #   # #  #   #   #   #  #   # ##  \033[0m\r\n");
					bt_UARTsend("\033[42m");
					bt_UARTsend("    #  #  ####  #   #   ###   #    #   #   #   #  #   ##    \033[0m\r\n");
					bt_UARTsend("\033[42m");
					bt_UARTsend(" #  #  #  #     #   #  #  #   #    #   #   #   #  #   # ##  \033[0m\r\n");
					bt_UARTsend("\033[42m");
					bt_UARTsend(" ###   ##  ### ### ### ### # ###  ### ### ### ###### ### ## \033[0m\r\n");
					for(temp1 = 0; temp1 < 2; temp1++)
					{
						bt_UARTsend("\033[42m");
						for(temp2 = 0; temp2 < 60; temp2++)
						{
							bt_UARTsend(" ");
						}
						bt_UARTsend("\033[0m");
						bt_UARTsend("\r\n");
					}
					bt_UARTsend("\033[0m");
					bt_UARTsend("\r\n");
		} break;
		case 1: {
					bt_UARTsend("\033[31m");
					bt_UARTsend(" +---------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("---------+");md();bt_UARTsend("\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend("  _____    _____");md();bt_UARTsend("_  __   __  ____");md();bt_UARTsend("__  ______  ____");md();bt_UARTsend("__       |\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend(" /\\  __`-./\\  __");md();bt_UARTsend(" \\ \\ \\ /\\ \\ \\  _");md();bt_UARTsend("__\\/\\  ___\\ \\  _");md();bt_UARTsend("_ \\      |\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend("/  \\ \\ `\\ \\ \\ \\_");md();bt_UARTsend("\\ \\ \\ `-.\\ \\ \\ \\");md();bt_UARTsend(" ___ \\ \\__   \\ \\");md();bt_UARTsend("_\\ \\     |\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend("\\   \\ \\  \\ \\ \\  ");md();bt_UARTsend("_  \\ \\      \\ \\ ");md();bt_UARTsend("\\\\_ \\ \\  _\\   \\ ");md();bt_UARTsend(" __`.    |\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend(" \\   \\ \\_/ |  \\ \\");md();bt_UARTsend(" \\ \\ \\ \\`-. \\ \\ ");md();bt_UARTsend("\\_\\ \\ \\ \\____ \\ ");md();bt_UARTsend("\\ \\ \\   |\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend("  \\   \\____/   \\");md();bt_UARTsend(" \\ \\_\\ \\_\\  \\_\\ ");md();bt_UARTsend("\\_____\\ \\_____\\ ");md();bt_UARTsend("\\_\\ \\ \\  |\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend("   \\  /   / \\  /");md();bt_UARTsend(" / / / / /  / / ");md();bt_UARTsend("/     / /     / ");md();bt_UARTsend("/ / / /  |\r\n");md();
					bt_UARTsend(" | ");md();bt_UARTsend("    \\/___/   \\/_");bt_UARTsend("/\\/_/ /_/ \\/_/ /");md();bt_UARTsend("_____/ /_____/ /");md();bt_UARTsend("_/\\/_/   |\r\n");md();
					bt_UARTsend(" |              ");bt_UARTsend("                ");bt_UARTsend("                ");bt_UARTsend("            |\r\n");
					md();bt_UARTsend(" +---------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("-----------------");md();bt_UARTsend("---------+");md();bt_UARTsend("\r\n");md();
					bt_UARTsend("\033[0m");
					bt_UARTsend("\r\n");
		} break;
		case 2: {
					//nothing yet

		} break;
		default: break;
	}

}
void turnTimes(void)
{
	int iterator=0;
	int sum=0;
	int temp=0;
	int decimal=0;
	bt_UARTsend("Turn Times - Left: ");
	for ( iterator = 0 ; iterator < 200 ; iterator++ )
	{
		sum+=(_gStepMap[iterator]+(sortCount));
		if (iterator==49)
		{
			temp=sum/10;
			bt_UARTsend(itoa(temp,10));
			bt_UARTputc('.');
			bt_UARTsend(itoa(sum-(temp*10),10));
			sum=0;
			bt_UARTsend("mS | Right: ");
		}
		else if (iterator==99)
		{

			temp=sum/10;
			bt_UARTsend(itoa(temp,10));
			bt_UARTputc('.');
			bt_UARTsend(itoa(sum-(temp*10),10));
			sum=0;
		}
	}
	bt_UARTsend("mS | 180: ");

	temp=sum/10;
	bt_UARTsend(itoa(temp,10));
	bt_UARTputc('.');
	bt_UARTsend(itoa(sum-(temp*10),10));
	bt_UARTsend("mS\r\n");


	//print PWM speed as well
	int pwmS = 	1000*_period / ROM_SysCtlClockGet();

	bt_UARTsend("PWM Period: ");
	bt_UARTsend(itoa(pwmS, 10));
	bt_UARTsend(" mS\tDuty Cycle: ");
	switch(calibrateState)
	{
	case 0: bt_UARTsend(itoa(masterDuty0/10, 10)); break;
	case 1: bt_UARTsend(itoa(masterDuty1/10, 10)); break;
	case 2: bt_UARTsend(itoa(masterDuty2/10, 10)); break;
	default: bt_UARTsend("unknown\r\n"); break;
	}
	bt_UARTsend("%\r\n");
}

void print_list_header(void)
{
	bt_UARTsend("\r\n");
	bt_UARTsend("------------------------------------------------------------");
	bt_UARTsend("\r\n");
	bt_UARTsend("------------------------------------------------------------");
	bt_UARTsend("\r\n");
}

void print_bin_number(void)
{
	/*if(speak_on) SYN_Say((unsigned char *)Volume"黑色塑料");
	if(speak_on) SYN_Say((unsigned char *) itoa(bin_black, 10));
	if(speak_on) SYN_Say((unsigned char *)Volume"白色塑料");
	if(speak_on) SYN_Say((unsigned char *) itoa(bin_white, 10));
	if(speak_on) SYN_Say((unsigned char *)Volume"钢");
	if(speak_on) SYN_Say((unsigned char *) itoa(bin_steel, 10));
	if(speak_on) SYN_Say((unsigned char *)Volume"铝");
	if(speak_on) SYN_Say((unsigned char *) itoa(bin_alumn, 10));*/
	bt_UARTsend("\r\n");
	bt_UARTsend("-----------------------------------------------\r\n");
	bt_UARTsend("White\tBlack\tSteel\tAlumn\tUnknown\tTotal\r\n");
	bt_UARTsend(itoa(bin_white, 10));
	bt_UARTsend("\t");
	bt_UARTsend(itoa(bin_black, 10));
	bt_UARTsend("\t");
	bt_UARTsend(itoa(bin_steel, 10));
	bt_UARTsend("\t");
	bt_UARTsend(itoa(bin_alumn, 10));
	bt_UARTsend("\t");
	bt_UARTsend(itoa(bin_dunno, 10));
	bt_UARTsend("\t");
	bt_UARTsend(itoa((bin_white+bin_black+bin_steel+bin_alumn+bin_dunno), 10));
	bt_UARTsend("\r\n");
	bt_UARTsend("-----------------------------------------------\r\n");
	bt_UARTsend("\r\n");
}
void print_ready(void)
{
	//bt_UARTsend("\r\nReady for sorting masters...\r\n");
	bt_UARTsend("\r\n");
	bt_UARTputc('R');
	mdd();
	bt_UARTputc('e');
	mdd();
	bt_UARTputc('a');
	mdd();
	bt_UARTputc('d');
	mdd();
	bt_UARTputc('y');mdd();
	bt_UARTputc(' ');mdd();
	bt_UARTputc('f');mdd();
	bt_UARTputc('o');mdd();
	bt_UARTputc('r');mdd();
	bt_UARTputc(' ');mdd();
	bt_UARTputc('s');mdd();
	bt_UARTputc('o');mdd();
	bt_UARTputc('r');mdd();
	bt_UARTputc('t');mdd();
	bt_UARTputc('i');mdd();
	bt_UARTputc('n');mdd();
	bt_UARTputc('g');mdd();
	bt_UARTputc('.');mdd();mdd();
	bt_UARTputc('.');mdd();mdd();mdd();
	bt_UARTputc('.');mdd();mdd();mdd();mdd();mdd();mdd();mdd();

	bt_UARTputc(' ');mdd();
	bt_UARTputc('m');mdd();mdd();
	bt_UARTputc('a');mdd();mdd();
	bt_UARTputc('s');mdd();mdd();
	bt_UARTputc('t');mdd();mdd();
	bt_UARTputc('e');mdd();mdd();
	bt_UARTputc('r');mdd();mdd();
	bt_UARTputc('s');mdd();mdd();
	bt_UARTputc('.');mdd();mdd();
	bt_UARTsend("\r\n");
}
